import Icon from '@/components/Icon'
import { ReactNode } from 'react'
import { useHistory } from 'react-router'
import styles from './index.module.scss'
type Props = {
  title?: ReactNode
  right?: ReactNode
  onBack?: () => void
  children?: ReactNode
}
export default function Index({ title, right, onBack, children }: Props) {
  const history = useHistory()
  const back = () => {
    onBack ? onBack() : history.goBack()
  }
  return (
    <div className={styles.root}>
      <div className="main" onClick={back}>
        {/* 后退按钮 */}
        <div className="left">
          <Icon type="iconfanhui" />
        </div>
        {/* 居中标题 */}
        <div className="title">{children || title}</div>
        {/* 右侧内容 */}
        <div className="right">{right}</div>
      </div>
    </div>
  )
}
